from data_interface import RepositoryInfo, CommitInfo, IssuePRInfo

architectures = [
    "arm",
    "arm64",
    "x86",
    "x86_64",
    "mips",
    "mipsel",
    "ppc",
    "ppc64",
    "s390",
    "s390x",
    "x32",
    "x64",
    "RISC-V"
]

INFERENCE_PROMPT = """
The following is information about a code repository that supports multiprocessor architectures and information about a commit in that repository.
Your task is to determine whether the commit is related to a particular processor architecture.
"""

SUMMARIZE_PROMPT = """
Below is the README.md file for a code repository, please summarize the usage of the repository within five sentences.
"""


def generate_inference_prompt(repository_info: RepositoryInfo, commit_info: CommitInfo,
                              issue_pr_info: IssuePRInfo = None) -> str:
    repository_prompt = f"""
    **Code Repository Information**
    
    * Title: {repository_info.title}
    * README Abstract: {repository_info.readme_abstract}
    """

    commit_prompt = f"""
    **A Commit Message in Repository**
    
    * Description: {commit_info.info}
    """

    for file_path in commit_info.comments.keys():
        if commit_info.comments[file_path] is None:
            continue
        commit_prompt += f"  * File Path: {file_path}\n"
        commit_prompt += "    * "
        for comment in commit_info.comments[file_path].values():
            commit_prompt += f"{comment},"
        commit_prompt += "\n"

    issue_pr_prompt = ""
    if issue_pr_info is not None:
        issue_pr_prompt = f"""
    * Relevant Issue or Pull Request\n
      * Title: {issue_pr_info.title}
      * Labels: {",".join(issue_pr_info.labels)}
      * Content: {issue_pr_info.body}"""

    query_prompt = """
    Please determine if the commit is related to a specific processor architecture, 
    if so, pick one from the list of architectures as your answer:"""

    query_prompt += ",".join(architectures)
    query_prompt += """
    if not, please answer "unrelated" only, most commits are "unrelated", most commits are "unrelated", please judge carefully.
    You must answer in one word."""
    return repository_prompt + commit_prompt + issue_pr_prompt + query_prompt
